using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using JGSY.CMS.LowCode.Platform.Infrastructure.Middleware;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Extensions
{
    /// <summary>
    /// 增强审计中间件配置扩展
    /// </summary>
    public static class EnhancedAuditExtensions
    {
        /// <summary>
        /// 添加增强审计服务
        /// </summary>
        public static IServiceCollection AddEnhancedAudit(this IServiceCollection services, Action<EnhancedAuditOptions>? configureOptions = null)
        {
            services.AddHttpContextAccessor();
            
            var options = new EnhancedAuditOptions();
            configureOptions?.Invoke(options);
            services.AddSingleton(options);
            
            return services;
        }

        /// <summary>
        /// 使用增强审计中间件
        /// </summary>
        public static IApplicationBuilder UseEnhancedAudit(this IApplicationBuilder app)
        {
            return app.UseMiddleware<EnhancedAuditMiddleware>();
        }
    }
}
